from flask import Blueprint, render_template, current_app
from markupsafe import Markup
import os
from PIL import Image
from applications.models import Article

from applications.common.curd import model_to_dicts, up_status, delete_one_by_id, get_one_by_id

test_a = Blueprint('test_a', __name__, url_prefix='/test/a')


@test_a.route('/<int:id>')
def index(id):
    res = get_one_by_id(Article, id)
    res.remark = Markup(res.remark)
    return render_template("index/112.html", res=res)

@test_a.route('/')
def getname():
    bpath = current_app.config.get('UPLOADED_PHOTOS_DEST')
    tpath = os.path.join(bpath, 'thumbnail')
    names = ''
    justname = '730'
    for file in os.listdir(tpath):
        # tfile=file[::-1]
        # tfile=tfile[tfile.find('.')+1: len(tfile)][::-1]
        names += file + ',' + str(file.find(justname)) + '|'
        # if file.find('730')>0:
        #     names+=file+','

    return names
